function wechatQrCode(options) {
    var url = "https://open.weixin.qq.com/connect/qrconnect?appid=" + options.appId + "&scope=" + options.scope + "&redirect_uri=" + options.redirect_uri + "&state=" + options.state + "&login_type=jssdk";
    if (options.self_redirect === true) {
        url += "&self_redirect=true";
    } else {
        url += "&self_redirect=false";
    }
    if (options.styletype) {
        url += '&styletype=' + options.styletype;
    }
    if (options.sizetype) {
        url += '&sizetype=' + options.sizetype;
    }
    if (options.bgcolor) {
        url += '&bgcolor=' + options.bgcolor;
    }
    if (options.rst) {
        url += "&rst=" + options.rst;
    }
    if (options.style) {
        url += "&style=" + options.style;
    }
    if (options.href) {
        url += "&href=" + options.href;
    }
    var iframe = document.createElement("iframe");
    iframe.src = url;
    iframe.frameBorder = "0";
    iframe.allowTransparency = "true";
    iframe.scrolling = "no";
    iframe.width = "380px";
    iframe.height = "360px";
    var qrView = document.getElementById(options.id);
    qrView.innerHTML = "";
    qrView.appendChild(iframe)
}
//登录
function doLogin() {
    var mobile = $('#login_mobile').val();
    var ranCode = $('#login_ran_code').val();
    var mobileCode = $('#login_mobile_code').val();
    if (!isMobile(mobile)) {
        $("#login_mobile").focus();
        $('#loginErr').text('请输入正确的手机号码！').fadeIn();
        return false
    } else if (ranCode === "") {
        $("#login_ran_code").focus();
        $('#loginErr').text("请输入图片验证码！").fadeIn();
        return false
    } else if (mobileCode === "") {
        $("#login_mobile_code").focus();
        $('#loginErr').text("请输入接收到的手机短信码！").fadeIn();
        return false
    } else {
        $('#loginErr').fadeOut().text('');
    }
    var loading = layer.load(2);
    $.ajax({
        url: '/auth/login.json',
        type: 'post', dataType: 'json',
        data: {"ranCode": ranCode, "type": 2, "mobile": mobile, "mobileCode": mobileCode},
        success: function (result) {
            //layer.msg(result.msg);
            if (result.code === 0) {
                location.href = qdxRedirect;
            } else {
                return layer.alert(result.msg);
            }
        },
        error: function (e) {
            return layer.alert("send error!");
        },
        complete: function () {
            layer.close(loading);
        }
    });
    return false;
}
//验证手机输入
function isMobile(val) {
    if (val == null || val === "") {
        return false;
    }
    var reg = /^1{1}[0-9]{10}$/;
    return reg.test(val);
}
//发送手机登录码
function sendMobileCode(type) {
    var mobile = $('#login_mobile').val();
    var ranCode = $('#login_ran_code').val();
    if (!isMobile(mobile)) {
        $("#login_mobile").focus();
        return layer.alert("请输入正确的手机号码！");
    }
    if (ranCode === "") {
        $("#login_ran_code").focus();
        return layer.alert("请输入验证码！");
    }
    var loading = layer.load(2, {time: 5 * 1000});
    $.ajax({
        url: '/ajax/sendCode.json',
        type: 'post', dataType: 'json',
        data: {"type": type, "ranCode": ranCode, "mobile": mobile},
        success: function (result) {
            //layer.msg(result.msg);
            if (result.code === 0) {
                var timeNum = 60; /*当点击获取验证码后设置60秒计时不可点击*/
                //设置按钮不可点击
                $('#btn_send_' + type).addClass('layui-btn-disabled').attr('onclick', '').text(timeNum + '秒后可点击');
                var timeTicket = setInterval(function () {
                    if (timeNum > 1) {
                        timeNum--;
                        $('#btn_send_' + type).text(timeNum + '秒后可点击');
                    } else {
                        $('#btn_send_' + type).removeClass('layui-btn-disabled').attr('onclick', 'sendMobileCode(\'' + type + '\')').text('获取' + type === 'register' ? '注册码' : '登录码');
                        clearInterval(timeTicket);
                    }
                }, 1000);
            } else {
                return layer.alert(result.msg);
            }
        },
        error: function (e) {
            return layer.alert("send error!");
        },
        complete: function () {
            layer.close(loading);
        }
    });
}